const ActivityController = require('@db/business/ActivityController');

const fileHandle = require('@utils/fileHandle');
const logger = require('@utils/logger');
const colors = require('colors')

const activityController = new ActivityController();

const activityApi = (server) => {

    // 获取活动列表
    server.get('/api/activities', async (req, res) => {
        const { page = 1, pageSize = 10, state, serial, name, is_deleted } = req.query;
        const filters = { state, serial, name, is_deleted };

        // console.log('ap.filters::', filters);
        // console.log('ap.filters.state::', filters.state);

        const result = await activityController.getActivitiesByFilter(filters, page, pageSize);
        res.json(result);
    });

    // 添加活动
    server.post('/api/activities', (req, res) => {
        const activity = req.body;
        // console.log('api createing activity::', activity);
        const result = activityController.insertActivity(activity);
        res.json(result);
    });

    // 删除活动
    server.delete('/api/activities/:id', async (req, res) => {
        const { id } = req.params;

        console.log(`删除活动调试：${id}`.blue)

        const result = activityController.deleteActivity(id);
        res.json(result);
    });
}

module.exports = { activityApi };